<template>
  <div class="login-panel">
    <h1 class="title">后台管理系统</h1>
    <el-tabs type="border-card" stretch v-model="currentTab">

      <el-tab-pane name="account">
        <template #label>
          <el-icon><user-filled /></el-icon>
          账号登录
        </template>
        <login-account ref="accountRef" />
      </el-tab-pane>

      <el-tab-pane name="phone">
        <template #label>
         <el-icon><iphone /></el-icon>
          手机登录
        </template>
        <login-phone ref="phoneRef" />
      </el-tab-pane>

    </el-tabs>

    <div class="account-control">
      <el-checkbox v-model="keepPassword">记住密码</el-checkbox>
      <el-link type="primary">忘记密码</el-link>
    </div>

    <el-button type="primary" class="login-btn" @click="handleLoginClick"
      >立即登录</el-button
    >
  </div>
</template>

<script>
import { defineComponent, ref } from 'vue'
import loginAccount from './loginAccount.vue'
import loginPhone from './loginPhone.vue'
export default defineComponent({
  components: { loginAccount, loginPhone },
  setup (props, context) {
    const currentTab = ref('account') // tabs 切换绑定属性
    const keepPassword = ref(false) // 是否记住密码
    const accountRef = ref()
    const phoneRef = ref()

    const handleLoginClick = () => {
      if (currentTab.value === 'account') { // 账号登录
        accountRef.value.loginAction(keepPassword.value) // 把用户点了记住密码这个布尔值传到子组件
      } else { //  手机号登录
        phoneRef.value.loginAction(keepPassword.value)
      }
    }
    return {
      currentTab,
      keepPassword,
      handleLoginClick,
      accountRef,
      phoneRef
    }
  }
})
</script>

<style lang="less" scoped>
.login-panel {
  margin-bottom: 150px;
  width: 360px;

  .title {
    text-align: center;
  }

  .account-control {
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
  }

  .login-btn {
    width: 100%;
    margin-top: 10px;
  }
}
</style>
